package util;

/**
 * Encapsulates a pair of object to one class
 *
 * @param <S> the first class
 * @param <T> the second calss
 */
public class Pair<S, T> {
	private S first;
	private T second;

	/**
	 * Create a pair form two instances
	 * @param first first object
	 * @param second second object
	 */
	public Pair(S first, T second) {
		this.first = first;
		this.second = second;
	}

	/**
	 * @return the first object
	 */
	public S getFirst() {
		return first;
	}

	/** 
	 * @return the second object
	 */
	public T getSecond() {
		return second;
	}

	public String toString() {
		return "(" + first + ", " + second + ")";
	}

	/**
	 * check equality (useful for Maps)
	 */
	public boolean equals(Object o) {
		if (!(o instanceof Pair))
			return false;

		Pair pair = (Pair) o;

		Object first = pair.getFirst();
		Object second = pair.getSecond();

		return (first.equals(getFirst())) && (second.equals(getSecond()));
	}

	/**
	 * get hashcode (useful for HasMap)
	 */
	public int hashCode() {
		return (first == null ? 0 : first.hashCode())
		^ (second == null ? 0 : second.hashCode());
	}
}
